// 长的生命周期可以转成短的

// Here, Rust infers a lifetime that is as short as possible.
// The two references are then coerced to that lifetime.
// 只要返回的不是引用，是返回值就没有什么说法了
fn multiply<'a>(first: &'a i32, second: &'a i32) -> i32 {
    first * second
}

// `<'a: 'b, 'b>` reads as lifetime `'a` is at least as long as `'b`.
// 生命周期a和生命周期相等
// Here, we take in an `&'a i32` and return a `&'b i32` as a result of coercion.
// 因此，把'a的变量返回为'b的变量才会没问题
fn choose_first<'a: 'b, 'b>(first: &'a i32, _: &'b i32) -> &'b i32 {
    first
}

fn main() {
    let first = 2; // Longer lifetime
    
    {
        let second = 3; // Shorter lifetime
        
        println!("The product is {}", multiply(&first, &second));
        println!("{} is the first", choose_first(&first, &second));
    };
}